package code.structure.manager.pop.view
{
	import com.patience.mvc.context.Command;
	
	import code.structure.manager.assist.ProjectAssistManager;
	import code.structure.manager.sound.MySoundManager;
	import code.tools.behavior.achieve.AppaerMove;
	import code.tools.behavior.achieve.AppearAlpha;
	import code.tools.behavior.achieve.AppearBitmapScale;
	import code.tools.behavior.achieve.AppearNormal;
	import code.tools.behavior.achieve.AppearScale;
	import code.tools.behavior.achieve.DisappearAlpha;
	import code.tools.behavior.achieve.DisappearBitmapScale;
	import code.tools.behavior.achieve.DisappearMove;
	import code.tools.behavior.achieve.DisappearNormal;
	import code.tools.behavior.achieve.DisappearScale;
	import code.tools.commponents.Alignment;
	import code.tools.sound.src.SoundName;
	import code.untils.CommandNameConst;

	/**
	 * 弹窗父类
	 * @author CYang
	 */
	public class Windows extends Panel
	{
		/**
		 * 直接出现消失模式
		 */
		public static const MODE_NORMAL:int = 0;
		/**
		 * 缩放模式
		 */
		public static const MODE_SCALE:int = 1;
		/**
		 * 透明度模式
		 */
		public static const MODE_ALPHA:int = 2;
		/**
		 * 弹窗的优先级
		 */
		public var priority:int;
		/**
		 * 弹窗是否显示背景遮罩
		 */
		public var bgVisible:Boolean;
		/**
		 *对齐方式，默认居中 ，其他居中方式 见枚举：Alignment
		 */		
		public var align:int = Alignment.MIDDLE_CENTER;
		
		/**
		 *弹框偏移量 
		 */
		public var popOffsetX:Number = 0;
		/**
		 *弹框偏移量 
		 */
		public var popOffsetY:Number = 0;
		/**
		 *	是否需要礼花 
		 */		
		public var isNeedFireWorks:Boolean = false;
		/**
		 * 构造函数 
		 * @param	control 弹窗控制类
		 */
		public function Windows()
		{
			
		}
		/**
		 * 重写父类的初始化方法 读取资源
		 */
		override protected function initializePanel():void 
		{
			//override buy sub class……
			/*try {
				_mLibs = PanelData.ILibWin.getResourceByName(_sClassName);
				_mMain.addChild(_mLibs);
				trace(_sClassName, _mLibs);
			}catch (e:Error) { trace("Error::", _sClassName, e) }*/
		}
		/**
		 * 出现消失工厂
		 * 若使用的是AppearScale，并且类中有用到textbutton按钮的，则需要在类中重写appFunction()方法，在方法中分别调用所有textbutton的draw方法
		 * @param	app
		 * @param	dis
		 */
		protected function appearFactory(app:int, dis:int):void
		{
			switch(app)
			{
				case 0:
					_IAppear = new AppearNormal(_sMain, appFunction);
				break;
				case 1:
					_IAppear = new AppearScale(_sMain, appFunction);
				break;
				case 2:
					_IAppear = new AppearAlpha(_sMain, appFunction);
				break;
				case 3:
					_IAppear = new AppaerMove(_sMain, appFunction);
				break;
				case 4:
					_IAppear = new AppearBitmapScale(_sMain, appFunction);
				break;
				
			}
			switch(dis)
			{
				case 0:
					_IDisappear = new DisappearNormal(_sMain, disFunction);
				break;
				case 1:
					_IDisappear = new DisappearScale(_sMain, disFunction);
				break;
				case 2:
					_IDisappear = new DisappearAlpha(_sMain, disFunction);
				break;
				case 3:
					_IDisappear = new DisappearMove(_sMain, disFunction);
					break;
				case 4:
					_IDisappear = new DisappearBitmapScale(_sMain, disFunction);
				break;
			}
		}
		override public function appear():void
		{
			super.appear();
			if(isNeedFireWorks)
				MySoundManager.playSound(SoundName.LEVEL_UP);
			else
				MySoundManager.playSound(SoundName.POP_WINDOW, 0.5);
		}
		/**
		 * 出现后调用的方法
		 */
		protected function appFunction():void
		{
			if(ProjectAssistManager.getIntance().feedRequestManager)
			ProjectAssistManager.getIntance().feedRequestManager.controller.dispatch(new Command(CommandNameConst.COMMAND_CLOSE_GO_TIPS_BY_FRIENDS));
		}
		/**
		 * 隐藏后调用的方法
		 * 先移除 再判断后面有无面板
		 */
		private function disFunction():void
		{
			this.visible = false;
			this.bVisible = false;
			try {
				ProjectAssistManager.getIntance().popManager.hideAppointWindow(this);
			}catch (e:Error) { trace("调用WindowManager关闭窗体失败") }
		}
		/**
		 * 窗体共同释放资源方法
		 */
		override public function dispose():void
		{
			subDispose();
			
		}
		/**
		 * 子类自己需要释放的资源
		 */
		protected function subDispose():void
		{
			//override by sub class;
			trace("子类释放资源")
		}
		
		override public function get visible():Boolean
		{
			return _sMain.visible;
		}
	}
}